//
//  HZFurnitureAction.m
//  Model
//
//  Created by zeb-apple on 2017/5/31.
//  Copyright © 2017年 YDJH. All rights reserved.
//  家具的action

#import "HZFurnitureAction.h"
#import "HZFurniture.h"
#import "HZRoom.h"
#import "HZRoomLogic.h"
#import "HZFurniture_Header.h"


@implementation HZFurnitureAction

+(HZFurnitureAction*)standardHZFurnitureAction
{
    __strong static HZFurnitureAction *_sharedObject = nil;
    @synchronized(self) {//同步 执行 防止多线程操作
        if (_sharedObject == nil) {
            _sharedObject = [[self alloc] init];
        }
    }
    return _sharedObject;
}
- (HZRoom *)enterAction:(HZFurniture *)furniture withObject:(NSMutableArray *)buildingStructure {
    

    
    //当前房间的位置
    NSIndexPath *indexPath = [HZRoomLogic goBackBuildingCurrentIndex];
    HZRoom *lastRoom = buildingStructure[indexPath.section][indexPath.row];
    //更新上个房间的状态
    lastRoom.roomState = RoomState_Came;
    
    //返回建筑轮廓
    NSString *structure = [HZRoomLogic goBackStructure];
    NSArray *structures =  [structure componentsSeparatedByString:@","];
  //  NSString *floorNum = [structures firstObject];
    NSString *roomNum = [structures lastObject];
    
    if ([furniture.furnitureName rangeOfString:Staircase_Type].location != NSNotFound) { //楼梯
        if ([furniture.indexPath isEqual:indexPath]) { //本房间 上楼
            HZRoom *tempRoom = buildingStructure[indexPath.section + 1][0];
            if (![tempRoom.roomCategory isEqualToString:RoomCategory_InsideLobby]) { //不是大厅
                if ([furniture.position_type isEqualToString:Staircase_left]) { //大厅左边
                    return buildingStructure[indexPath.section + 1][0];
                }else if ([furniture.position_type isEqualToString:Staircase_right]) { //大厅右边
                    return buildingStructure[indexPath.section + 1][roomNum.integerValue - 1];
                }else {
                    return buildingStructure[indexPath.section + 1][indexPath.row];
                }
            }else {
               return tempRoom;
            }
        }else { //下楼
            HZRoom *tempRoom = buildingStructure[indexPath.section - 1][0];
            if ([tempRoom.roomCategory isEqualToString:RoomCategory_InsideLobby]) { //是大厅
                return tempRoom;
            }else {
                return buildingStructure[indexPath.section - 1][indexPath.row];
            }
        }
    }else if ([furniture.furnitureName rangeOfString:Door_Type].location != NSNotFound) { //门
        if ([furniture.indexPath isEqual:indexPath]) { //本房间门 返回上个房间
            return buildingStructure[indexPath.section][indexPath.row-1];
        }else { //进入下个房间
            return buildingStructure[indexPath.section][indexPath.row+1];
        }
    }else {
        NSLog(@"该家具不具备进入功能");
    }
    
    return nil;
}
@end
